package com.yfproject.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yfproject.service.impl.LabelServiseImpl;

@RestController
@RequestMapping("/lable")
public class LableController3 {

	@Autowired
	LabelServiseImpl labelServiseImpl;
	
	/**
	 * 插入标签信息
	 * @param name
	 * @param level
	 * @param status
	 * @param parent_id
	 * @param description
	 * @return
	 */
	@RequestMapping(value = "/insert", method = RequestMethod.POST) 
	public Void insertLabel(@RequestParam(value = "name", required = true) String name,
			@RequestParam(value = "level", required = true) int level,
			@RequestParam(value = "status", defaultValue="2") int status,
			@RequestParam(value = "parent_id", required = true) Long parent_id,
			@RequestParam(value = "description", required = false) String description
			) {
		if(description != null) {
			labelServiseImpl.insertLabel(name,level,status,parent_id,description);
		}
		else{
			labelServiseImpl.insertLabel(name,level,status,parent_id);
		}
		return null;
	}
	
	
	/**
	 * 删除标签信息(将标签及其子标签状态更改为9)
	 * @param id
	 */
	@RequestMapping("/delete/{id}")
	public void delLabelInfoById(@PathVariable Long id) {
		labelServiseImpl.delLabel(id);	
	}
}
